<template>
	<view>
		<dsl-navbar title="我的资料" bgTopImg='#ffffff' isBack="true"></dsl-navbar>
		<view class="bg-white padding rowsb align-center solid-bottom" @click="avatarSet()">
			<view>头像</view>
			<view>
				<image :src="upImage" mode="aspectFill" class="round user_image"></image>
			</view>
		</view>
		<view class="bg-white padding rowsb align-center solid-bottom">
			<view>姓名</view>
			<view class="align-center">
				<view>
					<input type="text" value="" placeholder="请输入" v-model="username" />
				</view>
				<text class="cuIcon-right"></text>
			</view>
		</view>
		<view class="bg-white padding rowsb align-center solid-bottom" @click="sexTypeMen">
			<view>性别</view>
			<view>{{sex}} <text class="cuIcon-right"></text></view>
		</view>
		<view class="bg-white padding rowsb align-center solid-bottom">
			<view>地区</view>
			<view class="align-center">
				<text class="cuIcon-right"></text>
			</view>
		</view>
		<view class="bg-white padding rowsb align-center solid-bottom">
			<view>个人简介</view>
		</view>
		<textarea value="" placeholder="简单介绍一下自己" />
		<view class="padding text-center page-bg round text-white margin " @click="profile">
			保存
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: '',
				sexTypeMen: '',
				upImage: '',
				sex:'男'
			}
		},
		onLoad() {

		},
		methods: {

			//弹窗选择
			sexTypeMen() {
				let self = this
				uni.showActionSheet({
					itemList: ['男', '女'],
					success: function(res) {
						if (res.tapIndex == 0) {
							self.sexType = 1
							self.sex = '男'
						} else {
							self.sexType = 2
							self.sex = '女'
						}
					}
				});
			},
			//数据回显
			userData() {
				let user = app.userInfo
				this.upImage = user.avatar
				this.username = user.username // 昵称
				// this.sex = user
				if (user.sex == 1) this.sex = '男'
				else this.sex = '女'
				this.mobile = user.mobile
				this.sexType = user.sex


				// this.upImage = app.userInfo
			},


			//地址选择接口
			changeRegion(region) {
				console.log(region);
				this.sca_name = region[0].name + '/' + region[1].name + '/' + region[2].name
				console.log('添加地址=====>', this.sca_name);
				let ssq = [];
				region.forEach(add => {
					ssq.push(add.name)
				})
				this.addressName = ssq;
			},

			profile() {
				let data = {
					avatar: this.upImage, //头像
					username: this.username, //用户名
					sex: this.sexType, //1是男  2 是女
					mobile: this.mobile, //手机号码  
					//少个昵称
				}
				console.log('[url]', profile);
				this.$axios.axiosFrom('POST', profile, data)
					.then((res) => {
						console.log('成功', res);
						if (res.code == 1) {
							this.$tools.showToast2('修改成功')
							setTimeout((res) => {
								console.log('[倒计时]', res);
								this.$tools.push('/pages/user/index')
							}, 1000)
						} else {
							this.$tools.showToast(res.msg)
						}
					})
			},
			//头像修改
			avatarSet() {
				updataImgList().then((res) => {
					if (res.code == 1) {
						this.upImage = res.data.url
						console.log('成功====>', res.data.url);
					} else {}
				})

			}
		}
	}
</script>

<style>
	.page-bg{
		background-color: #FFA200;
	}
	page {
		
	}

	.user_image {
		width: 100rpx;
		background-color: #EEEEEE;
		height: 100rpx;
	}

	input {
		font-size: 28rpx;
		text-align: right;
	}
	textarea{
		border: 1rpx solid #EEEEEE;
		margin: 0 auto;
		padding: 20rpx;
	}
</style>
